home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / perllocale.Z / perllocale
Encoding:
Text File  |  1998-10-28  |  58.8 KB  |  1,387 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       perllocale - Perl locale handling (internationalization and
  10.       localization)
  11.  
  12.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  13.       Perl supports    language-specific notions of data such as "is
  14.       this a letter", "what    is the uppercase equivalent of this
  15.       letter", and "which of these letters comes first".  These
  16.       are important    issues,    especially for languages other than
  17.       English--but also for    English: it would be naieve to imagine
  18.       that A-Za-z defines all the "letters"    needed to write    in
  19.       English. Perl    is also    aware that some    character other    than
  20.       '.' may be preferred as a decimal point, and that output
  21.       date representations may be language-specific.  The process
  22.       of making an application take    account    of its users'
  23.       preferences in such matters is called    iiiinnnntttteeeerrrrnnnnaaaattttiiiioooonnnnaaaalllliiiizzzzaaaattttiiiioooonnnn
  24.       (often abbreviated as    iiii11118888nnnn); telling such an application
  25.       about    a particular set of preferences    is known as
  26.       llllooooccccaaaalllliiiizzzzaaaattttiiiioooonnnn (llll11110000nnnn).
  27.  
  28.       Perl can understand language-specific    data via the
  29.       standardized (ISO C, XPG4, POSIX 1.c)    method called "the
  30.       locale system". The locale system is controlled per
  31.       application using one    pragma,    one function call, and several
  32.       environment variables.
  33.  
  34.       NNNNOOOOTTTTEEEE:    This feature is    new in Perl 5.004, and does not    apply
  35.       unless an application    specifically requests it--see the
  36.       section on _B_a_c_k_w_a_r_d _c_o_m_p_a_t_i_b_i_l_i_t_y.  The one exception    is
  37.       that _w_r_i_t_e() now aaaallllwwwwaaaayyyyssss uses the current locale - see    the
  38.       section on _N_O_T_E_S.
  39.  
  40.      PPPPRRRREEEEPPPPAAAARRRRIIIINNNNGGGG TTTTOOOO UUUUSSSSEEEE LLLLOOOOCCCCAAAALLLLEEEESSSS
  41.       If Perl applications are to understand and present your data
  42.       correctly according a    locale of your choice, aaaallllllll of the
  43.       following must be true:
  44.  
  45.       +o   YYYYoooouuuurrrr ooooppppeeeerrrraaaattttiiiinnnngggg ssssyyyysssstttteeeemmmm mmmmuuuusssstttt ssssuuuuppppppppoooorrrrtttt tttthhhheeee llllooooccccaaaalllleeee ssssyyyysssstttteeeemmmm.
  46.           If it does, you should find that the _s_e_t_l_o_c_a_l_e()
  47.           function is a documented part of its C library.
  48.  
  49.       +o   DDDDeeeeffffiiiinnnniiiittttiiiioooonnnnssss ffffoooorrrr llllooooccccaaaalllleeeessss tttthhhhaaaatttt yyyyoooouuuu uuuusssseeee mmmmuuuusssstttt    bbbbeeee iiiinnnnssssttttaaaalllllllleeeedddd.
  50.           You, or your system administrator, must make sure    that
  51.           this is the case.    The available locales, the location in
  52.           which they are kept, and the manner in which they    are
  53.           installed    all vary from system to    system.     Some systems
  54.           provide only a few, hard-wired locales and do not    allow
  55.           more to be added.     Others    allow you to add "canned"
  56.           locales provided by the system supplier.    Still others
  57.           allow you    or the system administrator to define and add
  58.           arbitrary    locales.  (You may have    to ask your supplier
  59.           to provide canned    locales    that are not delivered with
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  71.  
  72.  
  73.  
  74.           your operating system.)  Read your system    documentation
  75.           for further illumination.
  76.  
  77.       +o   PPPPeeeerrrrllll mmmmuuuusssstttt    bbbbeeeelllliiiieeeevvvveeee    tttthhhhaaaatttt tttthhhheeee llllooooccccaaaalllleeee    ssssyyyysssstttteeeemmmm iiiissss ssssuuuuppppppppoooorrrrtttteeeedddd.
  78.           If it does, perl -V:d_setlocale will say that the    value
  79.           for d_setlocale is define.
  80.  
  81.       If you want a    Perl application to process and    present    your
  82.       data according to a particular locale, the application code
  83.       should include the use locale    pragma (see the    section    on _T_h_e
  84.       _u_s_e _l_o_c_a_l_e _p_r_a_g_m_a) where appropriate,    and aaaatttt lllleeeeaaaasssstttt oooonnnneeee of
  85.       the following    must be    true:
  86.  
  87.       +o   TTTThhhheeee llllooooccccaaaalllleeee----ddddeeeetttteeeerrrrmmmmiiiinnnniiiinnnngggg eeeennnnvvvviiiirrrroooonnnnmmmmeeeennnntttt vvvvaaaarrrriiiiaaaabbbblllleeeessss ((((sssseeeeeeee    tttthhhheeee
  88.           sssseeeeccccttttiiiioooonnnn oooonnnn _E_N_V_I_R_O_N_M_E_N_T) must be correctly    set up at the
  89.           time the application is started, either by yourself or
  90.           by whoever set up    your system account.
  91.  
  92.       +o   TTTThhhheeee aaaapppppppplllliiiiccccaaaattttiiiioooonnnn mmmmuuuusssstttt sssseeeetttt iiiittttssss oooowwwwnnnn llllooooccccaaaalllleeee using the    method
  93.           described    in the section on _T_h_e _s_e_t_l_o_c_a_l_e    _f_u_n_c_t_i_o_n.
  94.  
  95.      UUUUSSSSIIIINNNNGGGG LLLLOOOOCCCCAAAALLLLEEEESSSS
  96.       TTTThhhheeee uuuusssseeee llllooooccccaaaalllleeee pppprrrraaaaggggmmmmaaaa
  97.  
  98.       By default, Perl ignores the current locale.    The use    locale
  99.       pragma tells Perl to use the current locale for some
  100.       operations:
  101.  
  102.       +o   TTTThhhheeee ccccoooommmmppppaaaarrrriiiissssoooonnnn ooooppppeeeerrrraaaattttoooorrrrssss (lt, le,    cmp, ge, and gt) and
  103.           the POSIX    string collation functions _s_t_r_c_o_l_l() and
  104.           _s_t_r_x_f_r_m()    use LC_COLLATE.     _s_o_r_t()    is also    affected if
  105.           used without an explicit comparison function, because it
  106.           uses cmp by default.
  107.  
  108.           NNNNooootttteeee:::: eq and ne are unaffected by    locale:    they always
  109.           perform a    byte-by-byte comparison    of their scalar
  110.           operands.     What's    more, if cmp finds that    its operands
  111.           are equal    according to the collation sequence specified
  112.           by the current locale, it    goes on    to perform a byte-by-
  113.           byte comparison, and only    returns    _0 (equal) if the
  114.           operands are bit-for-bit identical.  If you really want
  115.           to know whether two strings--which eq and    cmp may
  116.           consider different--are equal as far as collation    in the
  117.           locale is    concerned, see the discussion in the section
  118.           on _C_a_t_e_g_o_r_y _L_C__C_O_L_L_A_T_E: _C_o_l_l_a_t_i_o_n.
  119.  
  120.       +o   RRRReeeegggguuuullllaaaarrrr eeeexxxxpppprrrreeeessssssssiiiioooonnnnssss aaaannnndddd ccccaaaasssseeee----mmmmooooddddiiiiffffiiiiccccaaaattttiiiioooonnnn    ffffuuuunnnnccccttttiiiioooonnnnssss
  121.           (_u_c(), _l_c(), _u_c_f_i_r_s_t(), and _l_c_f_i_r_s_t()) use LC_CTYPE
  122.  
  123.       +o   TTTThhhheeee ffffoooorrrrmmmmaaaattttttttiiiinnnngggg ffffuuuunnnnccccttttiiiioooonnnnssss (_p_r_i_n_t_f(), _s_p_r_i_n_t_f() and
  124.           _w_r_i_t_e()) use LC_NUMERIC
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  137.  
  138.  
  139.  
  140.       +o   TTTThhhheeee PPPPOOOOSSSSIIIIXXXX    ddddaaaatttteeee ffffoooorrrrmmmmaaaattttttttiiiinnnngggg    ffffuuuunnnnccccttttiiiioooonnnn (_s_t_r_f_t_i_m_e()) uses
  141.           LC_TIME.
  142.  
  143.       LC_COLLATE, LC_CTYPE,    and so on, are discussed further in
  144.       the section on _L_O_C_A_L_E    _C_A_T_E_G_O_R_I_E_S.
  145.  
  146.       The default behavior is restored with    the no locale pragma,
  147.       or upon reaching the end of block enclosing use locale.
  148.  
  149.       The string result of any operation that uses locale
  150.       information is tainted, as it    is possible for    a locale to be
  151.       untrustworthy.  See the section on _S_E_C_U_R_I_T_Y.
  152.  
  153.       TTTThhhheeee sssseeeettttllllooooccccaaaalllleeee    ffffuuuunnnnccccttttiiiioooonnnn
  154.  
  155.       You can switch locales as often as you wish at run time with
  156.       the _P_O_S_I_X::_s_e_t_l_o_c_a_l_e() function:
  157.  
  158.           # This functionality not usable prior    to Perl    5.004
  159.           require 5.004;
  160.  
  161.           # Import locale-handling tool    set from POSIX module.
  162.           # This example uses: setlocale -- the    function call
  163.           #               LC_CTYPE    -- explained below
  164.           use POSIX qw(locale_h);
  165.  
  166.           # query and save the old locale
  167.           $old_locale =    setlocale(LC_CTYPE);
  168.  
  169.           setlocale(LC_CTYPE, "fr_CA.ISO8859-1");
  170.           # LC_CTYPE now in locale "French, Canada, codeset ISO    8859-1"
  171.  
  172.           setlocale(LC_CTYPE, "");
  173.           # LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG
  174.           # environment    variables.  See    below for documentation.
  175.  
  176.           # restore the    old locale
  177.           setlocale(LC_CTYPE, $old_locale);
  178.  
  179.       The first argument of    _s_e_t_l_o_c_a_l_e() gives the ccccaaaatttteeeeggggoooorrrryyyy,    the
  180.       second the llllooooccccaaaalllleeee.  The category tells in what aspect    of
  181.       data processing you want to apply locale-specific rules.
  182.       Category names are discussed in the section on _L_O_C_A_L_E
  183.       _C_A_T_E_G_O_R_I_E_S and the section on    _E_N_V_I_R_O_N_M_E_N_T.  The locale is
  184.       the name of a    collection of customization information
  185.       corresponding    to a particular    combination of language,
  186.       country or territory,    and codeset.  Read on for hints    on the
  187.       naming of locales: not all systems name locales as in    the
  188.       example.
  189.  
  190.       If no    second argument    is provided and    the category is
  191.       something else than LC_ALL, the function returns a string
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  203.  
  204.  
  205.  
  206.       naming the current locale for    the category.  You can use
  207.       this value as    the second argument in a subsequent call to
  208.       _s_e_t_l_o_c_a_l_e().
  209.  
  210.       If no    second argument    is provided and    the category is
  211.       LC_ALL, the result is    implementation-dependent.  It may be a
  212.       string of concatenated locales names (separator also
  213.       implementation-dependent) or a single    locale name.  Please
  214.       consult your the _s_e_t_l_o_c_a_l_e(_3)    manpage    for details.
  215.  
  216.       If a second argument is given    and it corresponds to a    valid
  217.       locale, the locale for the category is set to    that value,
  218.       and the function returns the now-current locale value.  You
  219.       can then use this in yet another call    to _s_e_t_l_o_c_a_l_e().     (In
  220.       some implementations,    the return value may sometimes differ
  221.       from the value you gave as the second    argument--think    of it
  222.       as an    alias for the value you    gave.)
  223.  
  224.       As the example shows,    if the second argument is an empty
  225.       string, the category's locale    is returned to the default
  226.       specified by the corresponding environment variables.
  227.       Generally, this results in a return to the default that was
  228.       in force when    Perl started up: changes to the    environment
  229.       made by the application after    startup    may or may not be
  230.       noticed, depending on    your system's C    library.
  231.  
  232.       If the second    argument does not correspond to    a valid
  233.       locale, the locale for the category is not changed, and the
  234.       function returns _u_n_d_e_f.
  235.  
  236.       For further information about    the categories,    consult    the
  237.       _s_e_t_l_o_c_a_l_e(_3) manpage.
  238.  
  239.       FFFFiiiinnnnddddiiiinnnngggg llllooooccccaaaalllleeeessss
  240.  
  241.       For locales available    in your    system,    consult    also the
  242.       _s_e_t_l_o_c_a_l_e(_3) manpage to see whether it leads to the list of
  243.       available locales (search for    the _S_E_E    _A_L_S_O section).    If
  244.       that fails, try the following    command    lines:
  245.  
  246.           locale -a
  247.  
  248.           nlsinfo
  249.  
  250.           ls /usr/lib/nls/loc
  251.  
  252.           ls /usr/lib/locale
  253.  
  254.           ls /usr/lib/nls
  255.  
  256.       and see whether they list something resembling these
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  269.  
  270.  
  271.  
  272.           en_US.ISO8859-1     de_DE.ISO8859-1      ru_RU.ISO8859-5
  273.           en_US.iso88591      de_DE.iso88591      ru_RU.iso88595
  274.           en_US              de_DE          ru_RU
  275.           en              de          ru
  276.           english          german          russian
  277.           english.iso88591    german.iso88591      russian.iso88595
  278.           english.roman8              russian.koi8r
  279.  
  280.       Sadly, even though the calling interface for _s_e_t_l_o_c_a_l_e() has
  281.       been standardized, names of locales and the directories
  282.       where    the configuration resides have not been.  The basic
  283.       form of the name is _l_a_n_g_u_a_g_e__c_o_u_n_t_r_y/_t_e_r_r_i_t_o_r_y...._c_o_d_e_s_e_t, but
  284.       the latter parts after _l_a_n_g_u_a_g_e are not always present.  The
  285.       _l_a_n_g_u_a_g_e and _c_o_u_n_t_r_y are usually from    the standards IIIISSSSOOOO 3333111166666666
  286.       and IIIISSSSOOOO 666633339999, the two-letter abbreviations for    the countries
  287.       and the languages of the world, respectively.     The _c_o_d_e_s_e_t
  288.       part often mentions some IIIISSSSOOOO 8888888855559999 character set, the Latin
  289.       codesets.  For example, ISO 8859-1 is    the so-called "Western
  290.       codeset" that    can be used to encode most Western European
  291.       languages.  Again, there are several ways to write even the
  292.       name of that one standard.  Lamentably.
  293.  
  294.       Two special locales are worth    particular mention: "C"    and
  295.       "POSIX".  Currently these are    effectively the    same locale:
  296.       the difference is mainly that    the first one is defined by
  297.       the C    standard, the second by    the POSIX standard.  They
  298.       define the ddddeeeeffffaaaauuuulllltttt llllooooccccaaaalllleeee in which every program starts in
  299.       the absence of locale    information in its environment.     (The
  300.       _d_e_f_a_u_l_t default locale, if you will.)     Its language is
  301.       (American) English and its character codeset ASCII.
  302.  
  303.       NNNNOOOOTTTTEEEE:    Not all    systems    have the "POSIX" locale    (not all
  304.       systems are POSIX-conformant), so use    "C" when you need
  305.       explicitly to    specify    this default locale.
  306.  
  307.       LLLLOOOOCCCCAAAALLLLEEEE PPPPRRRROOOOBBBBLLLLEEEEMMMMSSSS
  308.  
  309.       You may encounter the    following warning message at Perl
  310.       startup:
  311.  
  312.           perl:    warning: Setting locale    failed.
  313.           perl:    warning: Please    check that your    locale settings:
  314.               LC_ALL = "En_US",
  315.               LANG = (unset)
  316.               are supported and    installed on your system.
  317.           perl:    warning: Falling back to the standard locale ("C").
  318.  
  319.       This means that your locale settings had LC_ALL set to
  320.       "En_US" and LANG exists but has no value.  Perl tried    to
  321.       believe you but could    not.  Instead, Perl gave up and    fell
  322.       back to the "C" locale, the default locale that is supposed
  323.       to work no matter what.  This    usually    means your locale
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  335.  
  336.  
  337.  
  338.       settings were    wrong, they mention locales your system    has
  339.       never    heard of, or the locale    installation in    your system
  340.       has problems (for example, some system files are broken or
  341.       missing).  There are quick and temporary fixes to these
  342.       problems, as well as more thorough and lasting fixes.
  343.  
  344.       TTTTeeeemmmmppppoooorrrraaaarrrriiiillllyyyy ffffiiiixxxxiiiinnnngggg llllooooccccaaaalllleeee pppprrrroooobbbblllleeeemmmmssss
  345.  
  346.       The two quickest fixes are either to render Perl silent
  347.       about    any locale inconsistencies or to run Perl under    the
  348.       default locale "C".
  349.  
  350.       Perl's moaning about locale problems can be silenced by
  351.       setting the environment variable PERL_BADLANG    to a non-zero
  352.       value, for example "1".  This    method really just sweeps the
  353.       problem under    the carpet: you    tell Perl to shut up even when
  354.       Perl sees that something is wrong.  Do not be    surprised if
  355.       later    something locale-dependent misbehaves.
  356.  
  357.       Perl can be run under    the "C"    locale by setting the
  358.       environment variable LC_ALL to "C".  This method is perhaps
  359.       a bit    more civilized than the    PERL_BADLANG approach, but
  360.       setting LC_ALL (or other locale variables) may affect    other
  361.       programs as well, not    just Perl.  In particular, external
  362.       programs run from within Perl    will see these changes.     If
  363.       you make the new settings permanent (read on), all programs
  364.       you run see the changes.  See    the _E_N_V_I_R_O_N_M_E_N_T    manpage    for
  365.       for the full list of relevant    environment variables and the
  366.       section on _U_S_I_N_G _L_O_C_A_L_E_S for their effects in    Perl.  Effects
  367.       in other programs are    easily deducible.  For example,    the
  368.       variable LC_COLLATE may well affect your ssssoooorrrrtttt    program    (or
  369.       whatever the program that arranges `records' alphabetically
  370.       in your system is called).
  371.  
  372.       You can test out changing these variables temporarily, and
  373.       if the new settings seem to help, put    those settings into
  374.       your shell startup files.  Consult your local    documentation
  375.       for the exact    details.  For in Bourne-like shells (sssshhhh, kkkksssshhhh,
  376.       bbbbaaaasssshhhh,    zzzzsssshhhh):
  377.  
  378.           LC_ALL=en_US.ISO8859-1
  379.           export LC_ALL
  380.  
  381.       This assumes that we saw the locale "en_US.ISO8859-1"    using
  382.       the commands discussed above.     We decided to try that
  383.       instead of the above faulty locale "En_US"--and in Cshish
  384.       shells (ccccsssshhhh, ttttccccsssshhhh)
  385.  
  386.           setenv LC_ALL    en_US.ISO8859-1
  387.  
  388.       If you do not    know what shell    you have, consult your local
  389.       helpdesk or the equivalent.
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  401.  
  402.  
  403.  
  404.       PPPPeeeerrrrmmmmaaaannnneeeennnnttttllllyyyy ffffiiiixxxxiiiinnnngggg llllooooccccaaaalllleeee pppprrrroooobbbblllleeeemmmmssss
  405.  
  406.       The slower but superior fixes    are when you may be able to
  407.       yourself fix the misconfiguration of your own    environment
  408.       variables.  The _m_i_s(sing)configuration of the    whole system's
  409.       locales usually requires the help of your friendly system
  410.       administrator.
  411.  
  412.       First, see earlier in    this document about the    section    on
  413.       _F_i_n_d_i_n_g _l_o_c_a_l_e_s.  That tells how to find which locales are
  414.       really supported--and    more importantly, installed--on    your
  415.       system.  In our example error    message, environment variables
  416.       affecting the    locale are listed in the order of decreasing
  417.       importance (and unset    variables do not matter).  Therefore,
  418.       having LC_ALL    set to "En_US" must have been the bad choice,
  419.       as shown by the error    message.  First    try fixing locale
  420.       settings listed first.
  421.  
  422.       Second, if using the listed commands you see something
  423.       eeeexxxxaaaaccccttttllllyyyy (prefix matches do not count and case    usually
  424.       counts) like "En_US" without the quotes, then    you should be
  425.       okay because you are using a locale name that    should be
  426.       installed and    available in your system.  In this case, see
  427.       the section on _F_i_x_i_n_g    _s_y_s_t_e_m _l_o_c_a_l_e _c_o_n_f_i_g_u_r_a_t_i_o_n.
  428.  
  429.       PPPPeeeerrrrmmmmaaaannnneeeennnnttttllllyyyy ffffiiiixxxxiiiinnnngggg yyyyoooouuuurrrr llllooooccccaaaalllleeee ccccoooonnnnffffiiiigggguuuurrrraaaattttiiiioooonnnn
  430.  
  431.       This is when you see something like:
  432.  
  433.           perl:    warning: Please    check that your    locale settings:
  434.               LC_ALL = "En_US",
  435.               LANG = (unset)
  436.               are supported and    installed on your system.
  437.  
  438.       but then cannot see that "En_US" listed by the above-
  439.       mentioned commands.  You may see things like
  440.       "en_US.ISO8859-1", but that isn't the    same.  In this case,
  441.       try running under a locale that you can list and which
  442.       somehow matches what you tried.  The rules for matching
  443.       locale names are a bit vague because standardization is weak
  444.       in this area.     See again the the section on _F_i_n_d_i_n_g _l_o_c_a_l_e_s
  445.       about    general    rules.
  446.  
  447.       PPPPeeeerrrrmmmmaaaannnneeeennnnttttllllyyyy ffffiiiixxxxiiiinnnngggg ssssyyyysssstttteeeemmmm llllooooccccaaaalllleeee ccccoooonnnnffffiiiigggguuuurrrraaaattttiiiioooonnnn
  448.  
  449.       Contact a system administrator (preferably your own) and
  450.       report the exact error message you get, and ask them to read
  451.       this same documentation you are now reading.    They should be
  452.       able to check    whether    there is something wrong with the
  453.       locale configuration of the system.  The the section on
  454.       _F_i_n_d_i_n_g _l_o_c_a_l_e_s section is unfortunately a bit vague about
  455.       the exact commands and places    because    these things are not
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  467.  
  468.  
  469.  
  470.       that standardized.
  471.  
  472.       TTTThhhheeee llllooooccccaaaalllleeeeccccoooonnnnvvvv ffffuuuunnnnccccttttiiiioooonnnn
  473.  
  474.       The _P_O_S_I_X::_l_o_c_a_l_e_c_o_n_v() function allows you to get
  475.       particulars of the locale-dependent numeric formatting
  476.       information specified    by the current LC_NUMERIC and
  477.       LC_MONETARY locales.    (If you    just want the name of the
  478.       current locale for a particular category, use
  479.       _P_O_S_I_X::_s_e_t_l_o_c_a_l_e() with a single parameter--see the section
  480.       on _T_h_e _s_e_t_l_o_c_a_l_e _f_u_n_c_t_i_o_n.)
  481.  
  482.           use POSIX qw(locale_h);
  483.  
  484.           # Get    a reference to a hash of locale-dependent info
  485.           $locale_values = localeconv();
  486.  
  487.           # Output sorted list of the values
  488.           for (sort keys %$locale_values) {
  489.               printf "%-20s = %s\n", $_, $locale_values->{$_}
  490.           }
  491.  
  492.       _l_o_c_a_l_e_c_o_n_v() takes no    arguments, and returns aaaa rrrreeeeffffeeeerrrreeeennnncccceeee ttttoooo
  493.       a hash.  The keys of this hash are variable names for
  494.       formatting, such as decimal_point and    thousands_sep.    The
  495.       values are the corresponding,    er, values.  See the
  496.       localeconv entry in the _P_O_S_I_X    (_3) manpage for    a longer
  497.       example listing the categories an implementation might be
  498.       expected to provide; some provide more and others fewer.
  499.       You don't need an explicit use locale, because _l_o_c_a_l_e_c_o_n_v()
  500.       always observes the current locale.
  501.  
  502.       Here's a simple-minded example program that rewrites its
  503.       command-line parameters as integers correctly    formatted in
  504.       the current locale:
  505.  
  506.           # See    comments in previous example
  507.           require 5.004;
  508.           use POSIX qw(locale_h);
  509.  
  510.           # Get    some of    locale's numeric formatting parameters
  511.           my ($thousands_sep, $grouping) =
  512.                @{localeconv()}{'thousands_sep',    'grouping'};
  513.  
  514.           # Apply defaults if values are missing
  515.           $thousands_sep = ',' unless $thousands_sep;
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  533.  
  534.  
  535.  
  536.           # grouping and mon_grouping are packed lists
  537.           # of small integers (characters) telling the
  538.           # grouping (thousand_seps and    mon_thousand_seps
  539.           # being the group dividers) of numbers and
  540.           # monetary quantities.  The integers'    meanings:
  541.           # 255    means no more grouping,    0 means    repeat
  542.           # the    previous grouping, 1-254 means use that
  543.           # as the current grouping.  Grouping goes from
  544.           # right to left (low to high digits).     In the
  545.           # below we cheat slightly by never using anything
  546.           # else than the first    grouping (whatever that    is).
  547.           if ($grouping) {
  548.               @grouping    = unpack("C*", $grouping);
  549.           } else {
  550.               @grouping    = (3);
  551.           }
  552.  
  553.           # Format command line    params for current locale
  554.           for (@ARGV) {
  555.               $_ = int;       # Chop non-integer part
  556.               1    while
  557.               s/(\d)(\d{$grouping[0]}($|$thousands_sep))/$1$thousands_sep$2/;
  558.               print "$_";
  559.           }
  560.           print    "\n";
  561.  
  562.  
  563.      LLLLOOOOCCCCAAAALLLLEEEE CCCCAAAATTTTEEEEGGGGOOOORRRRIIIIEEEESSSS
  564.       The following    subsections describe basic locale categories.
  565.       Beyond these,    some combination categories allow manipulation
  566.       of more than one basic category at a time.  See the section
  567.       on _E_N_V_I_R_O_N_M_E_N_T for a discussion of these.
  568.  
  569.       CCCCaaaatttteeeeggggoooorrrryyyy LLLLCCCC____CCCCOOOOLLLLLLLLAAAATTTTEEEE:::: CCCCoooollllllllaaaattttiiiioooonnnn
  570.  
  571.       In the scope of use locale, Perl looks to the    LC_COLLATE
  572.       environment variable to determine the    application's notions
  573.       on collation (ordering) of characters.  For example, 'b'
  574.       follows 'a' in Latin alphabets, but where do 'a' and 'aa'
  575.       belong?  And while 'color' follows 'chocolate' in English,
  576.       what about in    Spanish?
  577.  
  578.       The following    collations all make sense and you may meet any
  579.       of them if you "use locale".
  580.  
  581.           A B C    D E a b    c d e
  582.           A a B    b C c D    d D e
  583.           a A b    B c C d    D e E
  584.           a b c    d e A B    C D E
  585.  
  586.       Here is a code snippet to tell what alphanumeric characters
  587.       are in the current locale, in    that locale's order:
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 10/23/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  599.  
  600.  
  601.  
  602.           use locale;
  603.           print    +(sort grep /\w/, map {    chr() }    0..255), "\n";
  604.  
  605.       Compare this with the    characters that    you see    and their
  606.       order    if you state explicitly    that the locale    should be
  607.       ignored:
  608.  
  609.           no locale;
  610.           print    +(sort grep /\w/, map {    chr() }    0..255), "\n";
  611.  
  612.       This machine-native collation    (which is what you get unless
  613.       use locale has appeared earlier in the same block) must be
  614.       used for sorting raw binary data, whereas the    locale-
  615.       dependent collation of the first example is useful for
  616.       natural text.
  617.  
  618.       As noted in the section on _U_S_I_N_G _L_O_C_A_L_E_S, cmp    compares
  619.       according to the current collation locale when use locale is
  620.       in effect, but falls back to a byte-by-byte comparison for
  621.       strings that the locale says are equal. You can use
  622.       _P_O_S_I_X::_s_t_r_c_o_l_l() if you don't    want this fall-back:
  623.  
  624.           use POSIX qw(strcoll);
  625.           $equal_in_locale =
  626.               !strcoll("space and case ignored", "SpaceAndCaseIgnored");
  627.  
  628.       $equal_in_locale will    be true    if the collation locale
  629.       specifies a dictionary-like ordering that ignores space
  630.       characters completely    and which folds    case.
  631.  
  632.       If you have a    single string that you want to check for
  633.       "equality in locale" against several others, you might think
  634.       you could gain a little efficiency by    using _P_O_S_I_X::_s_t_r_x_f_r_m()
  635.       in conjunction with eq:
  636.  
  637.           use POSIX qw(strxfrm);
  638.           $xfrm_string = strxfrm("Mixed-case string");
  639.           print    "locale    collation ignores spaces\n"
  640.               if $xfrm_string eq strxfrm("Mixed-casestring");
  641.           print    "locale    collation ignores hyphens\n"
  642.               if $xfrm_string eq strxfrm("Mixedcase string");
  643.           print    "locale    collation ignores case\n"
  644.               if $xfrm_string eq strxfrm("mixed-case string");
  645.  
  646.       _s_t_r_x_f_r_m() takes a string and maps it into a transformed
  647.       string for use in byte-by-byte comparisons against other
  648.       transformed strings during collation.     "Under    the hood",
  649.       locale-affected Perl comparison operators call _s_t_r_x_f_r_m() for
  650.       both operands, then do a byte-by-byte    comparison of the
  651.       transformed strings.    By calling _s_t_r_x_f_r_m() explicitly    and
  652.       using    a non locale-affected comparison, the example attempts
  653.       to save a couple of transformations.    But in fact, it
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 10/23/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  665.  
  666.  
  667.  
  668.       doesn't save anything: Perl magic (see the section on    _M_a_g_i_c
  669.       _V_a_r_i_a_b_l_e_s in the _p_e_r_l_g_u_t_s manpage) creates the transformed
  670.       version of a string the first    time it's needed in a
  671.       comparison, then keeps this version around in    case it's
  672.       needed again.     An example rewritten the easy way with    cmp
  673.       runs just about as fast.  It also copes with null characters
  674.       embedded in strings; if you call _s_t_r_x_f_r_m() directly, it
  675.       treats the first null    it finds as a terminator.  don't
  676.       expect the transformed strings it produces to    be portable
  677.       across systems--or even from one revision of your operating
  678.       system to the    next.  In short, don't call _s_t_r_x_f_r_m()
  679.       directly: let    Perl do    it for you.
  680.  
  681.       Note:    use locale isn't shown in some of these    examples
  682.       because it isn't needed: _s_t_r_c_o_l_l() and _s_t_r_x_f_r_m() exist only
  683.       to generate locale-dependent results,    and so always obey the
  684.       current LC_COLLATE locale.
  685.  
  686.       CCCCaaaatttteeeeggggoooorrrryyyy LLLLCCCC____CCCCTTTTYYYYPPPPEEEE:::: CCCChhhhaaaarrrraaaacccctttteeeerrrr TTTTyyyyppppeeeessss
  687.  
  688.       In the scope of use locale, Perl obeys the LC_CTYPE locale
  689.       setting.  This controls the application's notion of which
  690.       characters are alphabetic.  This affects Perl's \w regular
  691.       expression metanotation, which stands    for alphanumeric
  692.       characters--that is, alphabetic and numeric characters.
  693.       (Consult the _p_e_r_l_r_e manpage for more information about
  694.       regular expressions.)     Thanks    to LC_CTYPE, depending on your
  695.       locale setting, characters like 'ae',    'd`', 'ss', and 'o' may
  696.       be understood    as \w characters.
  697.  
  698.       The LC_CTYPE locale also provides the    map used in
  699.       transliterating characters between lower and uppercase.
  700.       This affects the case-mapping    functions--_l_c(), lcfirst,
  701.       _u_c(),    and _u_c_f_i_r_s_t(); case-mapping interpolation with \l, \L,
  702.       \u, or \U in double-quoted strings and s/// substitutions;
  703.       and case-independent regular expression pattern matching
  704.       using    the i modifier.
  705.  
  706.       Finally, LC_CTYPE affects the    POSIX character-class test
  707.       functions--_i_s_a_l_p_h_a(),    _i_s_l_o_w_e_r(), and so on.  For example, if
  708.       you move from    the "C"    locale to a 7-bit Scandinavian one,
  709.       you may find--possibly to your surprise--that    "|" moves from
  710.       the _i_s_p_u_n_c_t()    class to _i_s_a_l_p_h_a().
  711.  
  712.       NNNNooootttteeee::::    A broken or malicious LC_CTYPE locale definition may
  713.       result in clearly ineligible characters being    considered to
  714.       be alphanumeric by your application.    For strict matching of
  715.       (mundane) letters and    digits--for example, in    command
  716.       strings--locale-aware    applications should use    \w inside a no
  717.       locale block.     See the section on _S_E_C_U_R_I_T_Y.
  718.  
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 10/23/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  731.  
  732.  
  733.  
  734.       CCCCaaaatttteeeeggggoooorrrryyyy LLLLCCCC____NNNNUUUUMMMMEEEERRRRIIIICCCC:::: NNNNuuuummmmeeeerrrriiiicccc FFFFoooorrrrmmmmaaaattttttttiiiinnnngggg
  735.  
  736.       In the scope of use locale, Perl obeys the LC_NUMERIC    locale
  737.       information, which controls an application's idea of how
  738.       numbers should be formatted for human    readability by the
  739.       _p_r_i_n_t_f(), _s_p_r_i_n_t_f(), and _w_r_i_t_e() functions.  String-to-
  740.       numeric conversion by    the _P_O_S_I_X::_s_t_r_t_o_d() function is    also
  741.       affected.  In    most implementations the only effect is    to
  742.       change the character used for    the decimal point--perhaps
  743.       from '.'  to ','.  These functions aren't aware of such
  744.       niceties as thousands    separation and so on.  (See the
  745.       section on _T_h_e _l_o_c_a_l_e_c_o_n_v _f_u_n_c_t_i_o_n if    you care about these
  746.       things.)
  747.  
  748.       Output produced by _p_r_i_n_t() is    nnnneeeevvvveeeerrrr affected by the current
  749.       locale: it is    independent of whether use locale or no    locale
  750.       is in    effect,    and corresponds    to what    you'd get from
  751.       _p_r_i_n_t_f() in the "C" locale.  The same    is true    for Perl's
  752.       internal conversions between numeric and string formats:
  753.  
  754.           use POSIX qw(strtod);
  755.           use locale;
  756.  
  757.           $n = 5/2;   #    Assign numeric 2.5 to $n
  758.  
  759.           $a = " $n"; #    Locale-independent conversion to string
  760.  
  761.           print    "half five is $n\n";       # Locale-independent    output
  762.  
  763.           printf "half five is %g\n", $n;  # Locale-dependent output
  764.  
  765.           print    "DECIMAL POINT IS COMMA\n"
  766.               if $n == (strtod("2,5"))[0]; # Locale-dependent conversion
  767.  
  768.  
  769.       CCCCaaaatttteeeeggggoooorrrryyyy LLLLCCCC____MMMMOOOONNNNEEEETTTTAAAARRRRYYYY::::    FFFFoooorrrrmmmmaaaattttttttiiiinnnngggg ooooffff mmmmoooonnnneeeettttaaaarrrryyyy aaaammmmoooouuuunnnnttttssss
  770.  
  771.       The C    standard defines the LC_MONETARY category, but no
  772.       function that    is affected by its contents.  (Those with
  773.       experience of    standards committees will recognize that the
  774.       working group    decided    to punt    on the issue.)    Consequently,
  775.       Perl takes no    notice of it.  If you really want to use
  776.       LC_MONETARY, you can query its contents--see the section on
  777.       _T_h_e _l_o_c_a_l_e_c_o_n_v _f_u_n_c_t_i_o_n--and use the information that    it
  778.       returns in your application's    own formatting of currency
  779.       amounts.  However, you may well find that the    information,
  780.       voluminous and complex though    it may be, still does not
  781.       quite    meet your requirements:    currency formatting is a hard
  782.       nut to crack.
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 10/23/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  797.  
  798.  
  799.  
  800.       LLLLCCCC____TTTTIIIIMMMMEEEE
  801.  
  802.       Output produced by _P_O_S_I_X::_s_t_r_f_t_i_m_e(),    which builds a
  803.       formatted human-readable date/time string, is    affected by
  804.       the current LC_TIME locale.  Thus, in    a French locale, the
  805.       output produced by the %B format element (full month name)
  806.       for the first    month of the year would    be "janvier".  Here's
  807.       how to get a list of long month names    in the current locale:
  808.  
  809.           use POSIX qw(strftime);
  810.           for (0..11) {
  811.               $long_month_name[$_] =
  812.               strftime("%B", 0, 0, 0, 1, $_, 96);
  813.           }
  814.  
  815.       Note:    use locale isn't needed    in this    example: as a function
  816.       that exists only to generate locale-dependent    results,
  817.       _s_t_r_f_t_i_m_e() always obeys the current LC_TIME locale.
  818.  
  819.       OOOOtttthhhheeeerrrr    ccccaaaatttteeeeggggoooorrrriiiieeeessss
  820.  
  821.       The remaining    locale category, LC_MESSAGES (possibly
  822.       supplemented by others in particular implementations)    is not
  823.       currently used by Perl--except possibly to affect the
  824.       behavior of library functions    called by extensions outside
  825.       the standard Perl distribution.
  826.  
  827.      SSSSEEEECCCCUUUURRRRIIIITTTTYYYY
  828.       Although the main discussion of Perl security    issues can be
  829.       found    in the _p_e_r_l_s_e_c manpage,    a discussion of    Perl's locale
  830.       handling would be incomplete if it did not draw your
  831.       attention to locale-dependent    security issues.  Locales--
  832.       particularly on systems that allow unprivileged users    to
  833.       build    their own locales--are untrustworthy.  A malicious (or
  834.       just plain broken) locale can    make a locale-aware
  835.       application give unexpected results.    Here are a few
  836.       possibilities:
  837.  
  838.       +o   Regular expression checks    for safe file names or mail
  839.           addresses    using \w may be    spoofed    by an LC_CTYPE locale
  840.           that claims that characters such as ">" and "|" are
  841.           alphanumeric.
  842.  
  843.       +o   String interpolation with    case-mapping, as in, say,
  844.           $dest = "C:\U$name.$ext",    may produce dangerous results
  845.           if a bogus LC_CTYPE case-mapping table is    in effect.
  846.  
  847.       +o   If the decimal point character in    the LC_NUMERIC locale
  848.           is surreptitiously changed from a    dot to a comma,
  849.           sprintf("%g", 0.123456e3)    produces a string result of
  850.           "123,456". Many people would interpret this as one
  851.           hundred and twenty-three thousand, four hundred and
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 10/23/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  863.  
  864.  
  865.  
  866.           fifty-six.
  867.  
  868.       +o   A    sneaky LC_COLLATE locale could result in the names of
  869.           students with "D"    grades appearing ahead of those    with
  870.           "A"s.
  871.  
  872.       +o   An application that takes    the trouble to use information
  873.           in LC_MONETARY may format    debits as if they were credits
  874.           and vice versa if    that locale has    been subverted.     Or it
  875.           might make payments in US    dollars    instead    of Hong    Kong
  876.           dollars.
  877.  
  878.       +o   The date and day names in    dates formatted    by _s_t_r_f_t_i_m_e()
  879.           could be manipulated to advantage    by a malicious user
  880.           able to subvert the LC_DATE locale.  ("Look--it says I
  881.           wasn't in    the building on    Sunday.")
  882.  
  883.       Such dangers are not peculiar    to the locale system: any
  884.       aspect of an application's environment which may be modified
  885.       maliciously presents similar challenges.  Similarly, they
  886.       are not specific to Perl: any    programming language that
  887.       allows you to    write programs that take account of their
  888.       environment exposes you to these issues.
  889.  
  890.       Perl cannot protect you from all possibilities shown in the
  891.       examples--there is no    substitute for your own    vigilance--
  892.       but, when use    locale is in effect, Perl uses the tainting
  893.       mechanism (see the _p_e_r_l_s_e_c manpage) to mark string results
  894.       that become locale-dependent,    and which may be untrustworthy
  895.       in consequence.  Here    is a summary of    the tainting behavior
  896.       of operators and functions that may be affected by the
  897.       locale:
  898.  
  899.       CCCCoooommmmppppaaaarrrriiiissssoooonnnn ooooppppeeeerrrraaaattttoooorrrrssss (lt, le,    ge, gt and cmp):
  900.           Scalar true/false    (or less/equal/greater)    result is
  901.           never tainted.
  902.  
  903.       CCCCaaaasssseeee----mmmmaaaappppppppiiiinnnngggg iiiinnnntttteeeerrrrppppoooollllaaaattttiiiioooonnnn (with \l, \L, \u or \U)
  904.           Result string containing interpolated material is
  905.           tainted if use locale is in effect.
  906.  
  907.       MMMMaaaattttcccchhhhiiiinnnngggg ooooppppeeeerrrraaaattttoooorrrr (m//):
  908.           Scalar true/false    result never tainted.
  909.  
  910.           Subpatterns, either delivered as a list-context result
  911.           or as $1 etc.  are tainted if use    locale is in effect,
  912.           and the subpattern regular expression contains \w    (to
  913.           match an alphanumeric character),    \W (non-alphanumeric
  914.           character), \s (white-space character), or \S (non
  915.           white-space character).  The matched-pattern variable,
  916.           $&, $` (pre-match), $' (post-match), and $+ (last    match)
  917.           are also tainted if use locale is    in effect and the
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 10/23/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  929.  
  930.  
  931.  
  932.           regular expression contains \w, \W, \s, or \S.
  933.  
  934.       SSSSuuuubbbbssssttttiiiittttuuuuttttiiiioooonnnn ooooppppeeeerrrraaaattttoooorrrr    (s///):
  935.           Has the same behavior as the match operator.  Also, the
  936.           left operand of =~ becomes tainted when use locale in
  937.           effect if    modified as a result of    a substitution based
  938.           on a regular expression match involving \w, \W, \s, or
  939.           \S; or of    case-mapping with \l, \L,\u or \U.
  940.  
  941.       IIIInnnn----mmmmeeeemmmmoooorrrryyyy ffffoooorrrrmmmmaaaattttttttiiiinnnngggg ffffuuuunnnnccccttttiiiioooonnnn    (sprintf()):
  942.           Result is    tainted    if "use    locale"    is in effect.
  943.  
  944.       OOOOuuuuttttppppuuuutttt ffffoooorrrrmmmmaaaattttttttiiiinnnngggg ffffuuuunnnnccccttttiiiioooonnnnssss (printf()    and write()):
  945.           Success/failure result is    never tainted.
  946.  
  947.       CCCCaaaasssseeee----mmmmaaaappppppppiiiinnnngggg ffffuuuunnnnccccttttiiiioooonnnnssss (lc(),    lcfirst(), uc(), ucfirst()):
  948.           Results are tainted if use locale    is in effect.
  949.  
  950.      strftime(), strxfrm()):
  951.       PPPPOOOOSSSSIIIIXXXX    llllooooccccaaaalllleeee----ddddeeeeppppeeeennnnddddeeeennnntttt ffffuuuunnnnccccttttiiiioooonnnnssss (localeconv(), strcoll(),
  952.           Results are never    tainted.
  953.  
  954.      isgraph(),    islower(), isprint(), ispunct(), isspace(), isupper(),
  955.      isxdigit()):
  956.       PPPPOOOOSSSSIIIIXXXX    cccchhhhaaaarrrraaaacccctttteeeerrrr ccccllllaaaassssssss    tttteeeessssttttssss (isalnum(), isalpha(), isdigit(),
  957.           True/false results are never tainted.
  958.  
  959.       Three    examples illustrate locale-dependent tainting.    The
  960.       first    program, which ignores its locale, won't run: a    value
  961.       taken    directly from the command line may not be used to name
  962.       an output file when taint checks are enabled.
  963.  
  964.           #/usr/local/bin/perl -T
  965.           # Run    with taint checking
  966.  
  967.           # Command line sanity    check omitted...
  968.           $tainted_output_file = shift;
  969.  
  970.           open(F, ">$tainted_output_file")
  971.               or warn "Open of $untainted_output_file failed: $!\n";
  972.  
  973.       The program can be made to run by "laundering" the tainted
  974.       value    through    a regular expression: the second example--
  975.       which    still ignores locale information--runs,    creating the
  976.       file named on    its command line if it can.
  977.  
  978.           #/usr/local/bin/perl -T
  979.  
  980.           $tainted_output_file = shift;
  981.           $tainted_output_file =~ m%[\w/]+%;
  982.           $untainted_output_file = $&;
  983.  
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 10/23/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  995.  
  996.  
  997.  
  998.           open(F, ">$untainted_output_file")
  999.               or warn "Open of $untainted_output_file failed: $!\n";
  1000.  
  1001.       Compare this with a similar but locale-aware program:
  1002.  
  1003.           #/usr/local/bin/perl -T
  1004.  
  1005.           $tainted_output_file = shift;
  1006.           use locale;
  1007.           $tainted_output_file =~ m%[\w/]+%;
  1008.           $localized_output_file = $&;
  1009.  
  1010.           open(F, ">$localized_output_file")
  1011.               or warn "Open of $localized_output_file failed: $!\n";
  1012.  
  1013.       This third program fails to run because $& is    tainted: it is
  1014.       the result of    a match    involving \w while use locale is in
  1015.       effect.
  1016.  
  1017.      EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT
  1018.       PERL_BADLANG
  1019.               A    string that can    suppress Perl's    warning    about
  1020.               failed locale settings at    startup.  Failure can
  1021.               occur if the locale support in the operating
  1022.               system is    lacking    (broken) in some way--or if
  1023.               you mistyped the name of a locale    when you set
  1024.               up your environment.  If this environment
  1025.               variable is absent, or has a value that does not
  1026.               evaluate to integer zero--that is, "0" or    ""--
  1027.               Perl will    complain about locale setting
  1028.               failures.
  1029.  
  1030.               NNNNOOOOTTTTEEEE: PERL_BADLANG only gives you    a way to hide
  1031.               the warning message.  The    message    tells about
  1032.               some problem in your system's locale support,
  1033.               and you should investigate what the problem is.
  1034.  
  1035.       The following    environment variables are not specific to
  1036.       Perl:    They are part of the standardized (ISO C, XPG4,    POSIX
  1037.       1.c) _s_e_t_l_o_c_a_l_e() method for controlling an application's
  1038.       opinion on data.
  1039.  
  1040.       LC_ALL      LC_ALL is    the "override-all" locale environment
  1041.               variable.    If set,    it overrides all the rest of
  1042.               the locale environment variables.
  1043.  
  1044.       LC_CTYPE    In the absence of    LC_ALL,    LC_CTYPE chooses the
  1045.               character    type locale.  In the absence of    both
  1046.               LC_ALL and LC_CTYPE, LANG    chooses    the character
  1047.               type locale.
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.      Page 16                        (printed 10/23/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  1061.  
  1062.  
  1063.  
  1064.       LC_COLLATE  In the absence of    LC_ALL,    LC_COLLATE chooses the
  1065.               collation    (sorting) locale.  In the absence of
  1066.               both LC_ALL and LC_COLLATE, LANG chooses the
  1067.               collation    locale.
  1068.  
  1069.       LC_MONETARY In the absence of    LC_ALL,    LC_MONETARY chooses
  1070.               the monetary formatting locale.  In the absence
  1071.               of both LC_ALL and LC_MONETARY, LANG chooses the
  1072.               monetary formatting locale.
  1073.  
  1074.       LC_NUMERIC  In the absence of    LC_ALL,    LC_NUMERIC chooses the
  1075.               numeric format locale.  In the absence of    both
  1076.               LC_ALL and LC_NUMERIC, LANG chooses the numeric
  1077.               format.
  1078.  
  1079.       LC_TIME     In the absence of    LC_ALL,    LC_TIME    chooses    the
  1080.               date and time formatting locale.    In the absence
  1081.               of both LC_ALL and LC_TIME, LANG chooses the
  1082.               date and time formatting locale.
  1083.  
  1084.       LANG          LANG is the "catch-all" locale environment
  1085.               variable.    If it is set, it is used as the    last
  1086.               resort after the overall LC_ALL and the
  1087.               category-specific    LC_....
  1088.  
  1089.      NNNNOOOOTTTTEEEESSSS
  1090.       BBBBaaaacccckkkkwwwwaaaarrrrdddd ccccoooommmmppppaaaattttiiiibbbbiiiilllliiiittttyyyy
  1091.  
  1092.       Versions of Perl prior to 5.004 mmmmoooossssttttllllyyyy ignored locale
  1093.       information, generally behaving as if    something similar to
  1094.       the "C" locale were always in    force, even if the program
  1095.       environment suggested    otherwise (see the section on _T_h_e
  1096.       _s_e_t_l_o_c_a_l_e _f_u_n_c_t_i_o_n).    By default, Perl still behaves this
  1097.       way for backward compatibility.  If you want a Perl
  1098.       application to pay attention to locale information, you mmmmuuuusssstttt
  1099.       use the use locale pragma (see the section on    _T_h_e _u_s_e    _l_o_c_a_l_e
  1100.       _P_r_a_g_m_a) to instruct it to do so.
  1101.  
  1102.       Versions of Perl from    5.002 to 5.003 did use the LC_CTYPE
  1103.       information if available; that is, \w    did understand what
  1104.       were the letters according to    the locale environment
  1105.       variables.  The problem was that the user had    no control
  1106.       over the feature:  if    the C library supported    locales, Perl
  1107.       used them.
  1108.  
  1109.       IIII11118888NNNN::::CCCCoooollllllllaaaatttteeee oooobbbbssssoooolllleeeetttteeee
  1110.  
  1111.       In versions of Perl prior to 5.004, per-locale collation was
  1112.       possible using the I18N::Collate library module.  This
  1113.       module is now    mildly obsolete    and should be avoided in new
  1114.       applications.     The LC_COLLATE    functionality is now
  1115.       integrated into the Perl core    language: One can use locale-
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 10/23/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  1127.  
  1128.  
  1129.  
  1130.       specific scalar data completely normally with    use locale, so
  1131.       there    is no longer any need to juggle    with the scalar
  1132.       references of    I18N::Collate.
  1133.  
  1134.       SSSSoooorrrrtttt ssssppppeeeeeeeedddd aaaannnndddd mmmmeeeemmmmoooorrrryyyy    uuuusssseeee iiiimmmmppppaaaaccccttttssss
  1135.  
  1136.       Comparing and    sorting    by locale is usually slower than the
  1137.       default sorting; slow-downs of two to    four times have    been
  1138.       observed.  It    will also consume more memory: once a Perl
  1139.       scalar variable has participated in any string comparison or
  1140.       sorting operation obeying the    locale collation rules,    it
  1141.       will take 3-15 times more memory than    before.     (The exact
  1142.       multiplier depends on    the string's contents, the operating
  1143.       system and the locale.) These    downsides are dictated more by
  1144.       the operating    system's implementation    of the locale system
  1145.       than by Perl.
  1146.  
  1147.       _w_r_i_t_e() and LC_NUMERIC
  1148.  
  1149.       Formats are the only part of Perl that unconditionally use
  1150.       information from a program's locale; if a program's
  1151.       environment specifies    an LC_NUMERIC locale, it is always
  1152.       used to specify the decimal point character in formatted
  1153.       output.  Formatted output cannot be controlled by use    locale
  1154.       because the pragma is    tied to    the block structure of the
  1155.       program, and,    for historical reasons,    formats    exist outside
  1156.       that block structure.
  1157.  
  1158.       FFFFrrrreeeeeeeellllyyyy aaaavvvvaaaaiiiillllaaaabbbblllleeee llllooooccccaaaalllleeee ddddeeeeffffiiiinnnniiiittttiiiioooonnnnssss
  1159.  
  1160.       There    is a large collection of locale    definitions at
  1161.       ftp://dkuug.dk/i18n/WG15-collection.    You should be aware
  1162.       that it is unsupported, and is not claimed to    be fit for any
  1163.       purpose.  If your system allows installation of arbitrary
  1164.       locales, you may find    the definitions    useful as they are, or
  1165.       as a basis for the development of your own locales.
  1166.  
  1167.       IIII11118888nnnn aaaannnndddd llll11110000nnnn
  1168.  
  1169.       "Internationalization" is often abbreviated as iiii11118888nnnn because
  1170.       its first and    last letters are separated by eighteen others.
  1171.       (You may guess why the internalin ...    internaliti ...    i18n
  1172.       tends    to get abbreviated.)  In the same way, "localization"
  1173.       is often abbreviated to llll11110000nnnn.
  1174.  
  1175.       AAAAnnnn iiiimmmmppppeeeerrrrffffeeeecccctttt ssssttttaaaannnnddddaaaarrrrdddd
  1176.  
  1177.       Internationalization,    as defined in the C and    POSIX
  1178.       standards, can be criticized as incomplete, ungainly,    and
  1179.       having too large a granularity.  (Locales apply to a whole
  1180.       process, when    it would arguably be more useful to have them
  1181.       apply    to a single thread, window group, or whatever.)     They
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 10/23/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  1193.  
  1194.  
  1195.  
  1196.       also have a tendency,    like standards groups, to divide the
  1197.       world    into nations, when we all know that the    world can
  1198.       equally well be divided into bankers,    bikers,    gamers,    and so
  1199.       on.  But, for    now, it's the only standard we've got.    This
  1200.       may be construed as a    bug.
  1201.  
  1202.      BBBBUUUUGGGGSSSS
  1203.       BBBBrrrrooookkkkeeeennnn ssssyyyysssstttteeeemmmmssss
  1204.  
  1205.       In certain systems, the operating system's locale support is
  1206.       broken and cannot be fixed or    used by    Perl.  Such
  1207.       deficiencies can and will result in mysterious hangs and/or
  1208.       Perl core dumps when the use locale is in effect.  When
  1209.       confronted with such a system, please    report in excruciating
  1210.       detail to <_p_e_r_l_b_u_g@_p_e_r_l._c_o_m>,    and complain to    your vendor:
  1211.       bug fixes may    exist for these    problems in your operating
  1212.       system.  Sometimes such bug fixes are    called an operating
  1213.       system upgrade.
  1214.  
  1215.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1216.       the isalnum entry in the _P_O_S_I_X (_3) manpage
  1217.  
  1218.       the isalpha entry in the _P_O_S_I_X (_3) manpage
  1219.  
  1220.       the isdigit entry in the _P_O_S_I_X (_3) manpage
  1221.  
  1222.       the isgraph entry in the _P_O_S_I_X (_3) manpage
  1223.  
  1224.       the islower entry in the _P_O_S_I_X (_3) manpage
  1225.  
  1226.       the isprint entry in the _P_O_S_I_X (_3) manpage,
  1227.  
  1228.       the ispunct entry in the _P_O_S_I_X (_3) manpage
  1229.  
  1230.       the isspace entry in the _P_O_S_I_X (_3) manpage
  1231.  
  1232.       the isupper entry in the _P_O_S_I_X (_3) manpage,
  1233.  
  1234.       the isxdigit entry in    the _P_O_S_I_X (_3) manpage
  1235.  
  1236.       the localeconv entry in the _P_O_S_I_X (_3)    manpage
  1237.  
  1238.       the setlocale    entry in the _P_O_S_I_X (_3) manpage,
  1239.  
  1240.       the strcoll entry in the _P_O_S_I_X (_3) manpage
  1241.  
  1242.       the strftime entry in    the _P_O_S_I_X (_3) manpage
  1243.  
  1244.       the strtod entry in the _P_O_S_I_X    (_3) manpage,
  1245.  
  1246.       the strxfrm entry in the _P_O_S_I_X (_3) manpage
  1247.  
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 10/23/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  1259.  
  1260.  
  1261.  
  1262.      HHHHIIIISSSSTTTTOOOORRRRYYYY
  1263.       Jarkko Hietaniemi's original _p_e_r_l_i_1_8_n._p_o_d heavily hacked by
  1264.       Dominic Dunlop, assisted by the perl5-porters.  Prose    worked
  1265.       over a bit by    Tom Christiansen.
  1266.  
  1267.       Last update: Thu Jun 11 08:44:13 MDT 1998
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 10/23/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))    1111////AAAAuuuugggg////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     PPPPEEEERRRRLLLLLLLLOOOOCCCCAAAALLLLEEEE((((1111))))
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.      Page 21                        (printed 10/23/98)
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.